<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script language="javascript" src="graphics.js"></script>
</head>
    <body>
		<?php
			if(isset($_POST['submit'])){
				include("classes/database.class.php");
				include("includes/define.php");
				$bd = new Database(MYSQL_DB_HOST,MYSQL_DB_LOGIN,MYSQL_DB_PASSWORD,MYSQL_DB_NAME);
				$bd->connect();
				$bd->query("INSERT INTO shapes VALUES ('".$_POST['shapeName']."','".$_POST['javascriptFunction']."');");
				$bd->close();
			}
        ?>
        <div id="adminPage">
        	<h2>Ajouter une forme</h2>
            <div id="newElement">
            	<div class="newColorBloc">
                    <div id="newShape">
                    </div>
                    <div class="colorForm">
                        <form action="" method="post">
                            <input type="text" name="shapeName" /><br/>
                            <input value="" onkeyup="createShape('newShape',document.getElementById('javascriptFunction').value,0,0,0)" type="text" name="javascriptFunction" id="javascriptFunction"/><br/>
                            <input type="submit" name="submit">
                        </form>
                    </div>
				</div>
			</div>
            <div id="elementList">
                <?php
					require_once("classes/database.class.php");
					require_once("includes/define.php");
					$bd = new Database(MYSQL_DB_HOST,MYSQL_DB_LOGIN,MYSQL_DB_PASSWORD,MYSQL_DB_NAME);
					$bd->connect();
					$allShapes = $bd->selectAll("shapes");
					while($shape = mysql_fetch_assoc($allShapes)){
						?>
                        <div class="existingColorBloc">
                            <h4><?php echo $shape['shapeName']; ?></h4>
                            <div id="<?php echo $shape['shapeName']; ?>"></div>
                            <div>
                                <span><?php echo $shape['javascriptFunction']; ?></span>
                            </div>
                            <script>createShape('<?php echo $shape['shapeName']; ?>','<?php echo $shape['javascriptFunction']; ?>',0,0,0);</script>
                        </div>
                        <?php
					}
				?>
            </div>
        </div>
        <script>createShape('newShape',document.getElementById('javascriptFunction').value,0,0,0);</script>
    </body>
</html>